package list;

public class LeetCode82 {
    public ListNode deleteDuplicates(ListNode head) {

        if (head == null || head.next == null) return head;

        ListNode dummy = new ListNode(-101, head);
        ListNode p = dummy;

        while (p.next != null && p.next.next != null) {
            ListNode p1 = p.next;
            ListNode p2 = p.next.next;
            if (p1.val != p2.val) {
                p = p.next;
                continue;
            }

            while (p1.val == p2.val) {
                p2 = p2.next;
                if (p2 ==null) break;
            }
            p.next = p2;
        }

        return dummy.next;
    }
}
